package leetcode.code784.LetterCasePermutation;

import java.util.ArrayList;
import java.util.List;

public class Solution78402 extends LetterCasePermutation {

	@Override
	public List<String> letterCasePermutation(String s) {
		return f(s.toCharArray(), 0);
	}

	private List<String> f(char[] s, int i) {
		List<String> result = new ArrayList<>();
		if (i == s.length - 1) {
			if (isNumber(s[i])) {
				result.add(s[i] + "");
			} else {
				result.add(s[i] + "");
				if (isLowerCase(s[i])) {
					result.add((char) (s[i] - 32) + "");
				} else {
					result.add((char) (s[i] + 32) + "");
				}
			}
		} else {
			List<String> rest = f(s, i + 1);
			for (String r : rest) {
				if (isNumber(s[i])) {
					result.add(s[i] + "" + r);
				} else {
					result.add(s[i] + "" + r);
					if (isLowerCase(s[i])) {
						result.add((char) (s[i] - 32) + "" + r);
					} else {
						result.add((char) (s[i] + 32) + "" + r);
					}
				}
			}
		}
		return result;
	}

	public boolean isUpperCase(char c) {
		return c >= 65 && c <= 90;
	}

	public boolean isLowerCase(char c) {
		return c >= 97 && c <= 122;
	}

	public boolean isNumber(char c) {
		return c >= 48 && c <= 57;
	}

	public static void main(String[] args) {
		Solution78402 so = new Solution78402();
		so.debug1();
//		System.out.println("1".toUpperCase());
//		System.out.println("1".toLowerCase());
//		System.out.println("a".toUpperCase());
//		System.out.println("a".toLowerCase());
		Character.isUpperCase('c');
	}

}
